Skip to content

v0.9.1: Cell 5 asks what each mask is; Register shows each step as it goes (#574 items 6-7) - #578

Draft
guijacquemet wants to merge 2 commits into
mainfrom
claude/register-masks-clarity
Draft

guijacquemet wants to merge 2 commits into
mainfrom
claude/register-masks-clarity

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Items 6 and 7 of #574 (owner's Colab test, 26 Nov 2026), for v0.9.1: the Register the masks step (cell 5 of MorphoBricks_Preprocessing_Cellpose). Draft: do not merge.

Item 6: what each mask is, asked clearly

The tick box "Declare Cells as separate objects" under a TOML preview is replaced. For each mask type, cell 5 now asks "Cells: what is this mask?" with no answer chosen:

  • ( ) Each object has its own number (label image: every cell/nucleus is a separate object)
  • ( ) Foreground / background only (binary mask)

The help line says why: "We ask because the two are measured differently, and we never guess which one a file is." The TOML is shown only folded, in a <details> element ("What registering it as separate objects adds to the experiment description").

Unchanged:

  • The recorded value. representation = "instances" is still saved through the app's Masks question. The test checks the exact [masks.Cells] section that gets written.
  • The refusal when nothing is chosen. The button stays disabled and register() returns False without changing anything. The blocker line now says "choose what Cells is" instead of "tick the declaration of Cells".

New: Cellpose gives each object its own number, so the binary answer is refused beside the button, with the reason (BINARY_REFUSED), and nothing records it. See the owner question below.

Item 7: Register reads the same files, and now shows each step

What Register reads, per file. I counted this on main with a patched opener (builtins.open, bytes read per opening), on the cell 4/5 test experiment of 4 images. The run uses verify_content, the notebook's default.

When Per image Per mask
Cell 5 shown 1 whole read (SHA-256 in refusal → open_run) none
Press that stops for the axes 1 whole read (refusal), plus header reads; the first image is also read for the axis viewers 1 header read
Press that registers 4 whole reads, each for the content SHA-256: (1) cell 5's refusal → open_run; (2) the app's run, compute_rows → with_content; (3) the run's check before it publishes, generation._commit → pipeline.check; (4) the app's tissue-mask step, which opens the run after it (notebook_tissue_mask.refresh → RunInputs.open). About 9 opens. The first image is also read about 4 more times in total by the two viewers that Check and save redraws twice (_refresh_confirmed_viewers) 5 whole reads: the run (mask_contents), its check before publishing (content_changed_masks), the mask step's fingerprints before and after reading (scan_fingerprints, check_scanned), and the pixels (read_tiff_plane, 1 piece_counts per mask). 7 opens

Reads after this PR: identical. Every phase has the same opens, bytes read, SHA-256 calls and piece_counts calls per file. I checked this at 512 px and at 256 px. tests/test_mask_register_progress.py pins the counts per file: images 4 whole reads, masks 5, opens 21/9/9/9 and 7 per mask; showing cell 5 reads each image whole once.

Why nothing was read less. Every one of these whole reads is either a check or the data itself:

  • refusal before the run. It must refuse changed images before anything is declared or published. The run's own content pass comes after, and reusing its hashes would leave a time-of-check gap.
  • The run's pre-publish check, and the mask step's before/after fingerprints. These are stability checks.
  • The tissue-mask step's opening and the viewer redraws. These are app (cell 3) behaviour. The viewer read also checks that the picture is of the checked image (expected fingerprint).

None of them could be removed without weakening a check. That is a question for the owner (below), so I changed none of them.

What is shown now. notebook_register_progress.RegisterWait uses the #567 mechanism (notebook_progress.Wait and its ticking thread). I did not build a new one. It shows:

  • one line, Step k of 5 · <step>, whose elapsed time keeps ticking;
  • under it, the step's own line. In step 1 these are the run's checks, counted: Reading each image whole for its content SHA-256 · 2 of 200 · ctrl/rep1/a.tif. In the other steps it is the app's own wait line for its folder check, its run (Preparing: … · n of N · <file>) and its mask step, copied into cell 5 as the app draws it (an observe that is removed when the step ends);
  • at the end, Took m:ss. (or Stopped after m:ss. after an error or interrupt).

The button is disabled while Register runs.

The five steps are:

  1. Checking the run cell 4 segmented and its images
  2. Checking the folders again with the masks folder (only when needed)
  3. Answering each mask and saving the description
  4. Running again (the histograms of unchanged images are reused)
  5. Describing the masks

How step 1 is counted, and the overlap with #575. Step 1 is counted through segmentation_cellpose_run.open_run(checking=). I applied #575's open_checks.py, run_inputs.open_checked and open_run/open_pinned hunks, plus its pyproject.toml and AGENTS.md lines for open_checks and its matching change to tests/test_notebook_cellpose_republished.py, byte for byte, so both PRs merge cleanly in either order. A trial merge of this branch with #575's head 85a4b06 has no conflicts, and its test_mask_register_progress.py, test_cellpose_folders_open.py and test_notebook_preprocessing_cellpose.py pass (51 tests). If #575 changes those hunks before it merges, this branch needs a rebase. I did not touch cell 4, notebook_open_progress.py or #575's register_step( test.

Identity evidence

I ran the same scripted press (cell 4 → cell 5 → axes stop → confirm → Register) on main and on this branch. I compared the run folder with normalized SHA-256 per file: the JSON is parsed, written_at, file mtimes, content_sha256 and manifest_sha256 are dropped, and temporary paths are replaced. Two runs of main differ only in those fields, because the test's OME-TIFFs carry a fresh UUID and cell 4 writes fresh masks.

  • All 10 files have identical normalized digests: check_headers.json, discovery_report.json/.txt, experiment_design.csv, image_qc.csv, mask_relationships.json, mask_representation.json, morphobricks.toml, plane_histograms.csv and run_manifest.json.
  • The CSVs, mask_relationships.json and morphobricks.toml are byte-identical.

Notebook

No cell changed. Cell 5 is still register_step(notebook, segmentation) / display(registration), which works with the pinned release and with this code. The markdown above cell 5 still shows the TOML and says "tick each one". It describes the pinned release's widget, so I left it until RELEASE_REF moves to v0.9.1. docs/user_guide.md describes the new step.

Tests

  • New: tests/test_mask_register_progress.py, 10 tests:
    • the question, its wording, no default, and the TOML only inside <details>;
    • nothing chosen is refused as before;
    • a binary answer is refused and nothing is declared;
    • the declaration that gets recorded is unchanged;
    • reads per file during Register, and when cell 5 is shown;
    • the step lines, the n of N per image with its name, the copied app lines and the ticking thread;
    • the first press shows the folder check;
    • refusal with and without checking gives the same result;
    • an interrupt leaves "Stopped after", and the copying stops.
  • Updated: tests/test_notebook_preprocessing_cellpose.py now uses .choices (the tick boxes are gone).
  • Focused runs: the new file with the cell 4/5, notebook-file, progress and run_inputs tests: 83 passed with ipywidgets 8.1.9. The new file and the cell 4/5 tests with ipywidgets 7.7.5: 31 passed (2 install tests deselected).
  • Checks: ruff check, ruff format --check and tools/check.py --rules pass.
  • Full tools/check.py at acfc4d5: ruff and format clean, 8822 passed, 32 skipped, code rules clean (rc 0). The skips come from the environment or are skipped by design: most need scikit-image, which is not installed; some are case-insensitive-file-system tests (this file system is case-sensitive); one is the release-only notebook pin; the rest are permission/root and by-design skips. None of them is in the files this PR touches. The first full run, at 0597be5, had 1 failure: test_notebook_cellpose_republished.py::test_a_run_published_while_it_is_opened_is_refused patched RunInputs.open, but open_run now goes through open_checked. The fix in acfc4d5 is v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575's own change to that test, byte for byte, and the merge with v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575 is still clean.

Owner questions

  1. Binary answer for Cellpose masks. Cell 5 now asks the question but registers only "each object has its own number", because Cellpose wrote label images and the recorded value had to stay instances. Choosing "foreground / background only" is refused, with the reason shown. Should a binary declaration of Cellpose masks be possible (recorded as representation = "binary")? That would change the recorded value, so I did not do it.
  2. Reads that are checks. Per Register press, each image is read whole 4 times. One of these is the tissue-mask step's opening of the run, right after the run's own pre-publish check. The first image is also read about 4 more times by viewer redraws in Check and save. Reducing either changes when a check is made: the tissue-mask step's run check, and the viewer's "picture of the checked image" fingerprint. Should either be reduced?
  3. Showing cell 5 reads each image whole once, with nothing on screen. This is refusal → open_run before the widget is displayed. v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575's "display first, then open" pattern for cell 4 could be applied to cell 5 once v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575 is merged.

Links #574.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

…items 6-7)

Item 6: the tick box "Declare <type> as separate objects" under a TOML
preview is replaced by a question per mask type with no answer chosen:
"Each object has its own number (label image: every cell/nucleus is a
separate object)" or "Foreground / background only (binary mask)", with
one sentence on why we ask. The TOML is shown only folded (<details>).
The recorded value (representation = "instances") and the refusal while
a mask type is unanswered are unchanged; a binary answer is refused beside
the button (Cellpose gives each object its own number), nothing records it.

Item 7: Register showed nothing in cell 5 while it read, per image of a
verify_content run, 4 whole files (SHA-256: cell 5's checks, the app's
run, its pre-publish check, the tissue-mask step's opening) and per mask
5 (run, pre-publish check, mask step fingerprints before/after, pixels).
Each read is a check or the data itself, so none is removed; reads per
file and the normalized run-folder digests are identical to main.
RegisterWait (notebook_progress.Wait and its ticking thread, #567) shows
"Step k of 5 · <step>" with the elapsed time and the step's own line:
the run's checks counted through open_run(checking=) (open_checks and
run_inputs.open_checked, identical to #575's hunks), and the app's own
wait lines copied while each step runs. Notebook cells are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
open_run now opens through run_inputs.open_checked (the hunks shared with
#575), so the test that publishes the run while it is opened patches that
function instead of RunInputs.open. Same change, byte for byte, as #575's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

Copy link
Copy Markdown
Contributor Author

Paused for v0.9.0 work: the owner has answered the three questions above. This is the TODO for later. Head is still acfc4d5; main (5c05644, #575 merged) is not merged in yet. #575's hunks copied here are byte-identical to main, so that merge should be clean.

TODO, owner decisions:

  • 1. Refuse binary for Cellpose masks. Keep the current refusal. Its message must say why: Cellpose gives each object its own number. Binary stays available for masks that come from elsewhere, if that path exists.
  • 2. Reuse a check within one Register press, only when the file's identity is unchanged.
    • Within one press, do not repeat a content SHA-256 already taken of a file if it is provably unchanged since then: same device, inode, size and mtime_ns, captured when it was hashed and compared at reuse.
    • Checks across presses stay. Everything at publish stays as strict as before.
    • Create the cache at the start of the press and pass it explicitly. Never use a module global. Any doubt means hash again.
    • Cover the tissue-mask step re-opening the run, and the viewer redraws during Check and save.
    • Prove the same normalized digests of the 10 run-folder files as before.
    • Tests: reads per file before and after, and a file changed mid-press is still caught (mutate it between two checks, keeping the mtime if possible; document what the identity rule cannot catch).
    • If any check would become weaker than "unchanged identity", stop and report.
  • 3. Opening cell 5: apply the v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575 show-first pattern. Show the widget first, then open the run with n-of-N progress and a timer. The cell text stays identical to the pinned main text, and ipywidgets 7.7 and 8 both work, as in v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) #575.

Generated by Claude Code

guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
Cell 5 asks what each mask is; Register shows each step as it goes (#574 items 6-7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbytvF3Gsa85ix8Ne2yMDW
guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
Fixes #580 on top of #578's Register wait: a failed re-check stops with
CHECK_FAILED and cell 3's reason; later presses and cell 5 run again refuse
without AttributeError; an unexpected error is shown in cell 5 (STOPPED) and
re-raised, with the wait's "Stopped after" line. Conflicts resolved so both
fixes hold; the tests of #581 use #578's question (choices, not ticks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbytvF3Gsa85ix8Ne2yMDW
guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
- Binary answer for a Cellpose mask: coded refusal (cellpose_mask_not_binary)
  saying why (Cellpose numbers each object); binary masks from elsewhere stay
  declarable in cell 3.
- Within one press, a content SHA-256 is reused while the file identity
  (st_dev, st_ino, st_size, st_mtime_ns, st_ctime_ns) is unchanged
  (content_memo.ContentMemo, created per press, passed explicitly; never at
  publication). Images: 2 whole reads per press instead of 4 (+1 for the
  former first press). A rewrite the identity cannot see is still refused by
  the run's check before it publishes (tested).
- Cell 5 is displayed first (shared notebook_shown_first.ShownFirst with
  cell 4), then opens the run with its n-of-N wait; cell text unchanged.
- One press: when the folders and image headers are unchanged since cell 3's
  check (register_checks.changes_since_check), the masks are paired with the
  app's Check the masks again and the confirmed axes are kept; otherwise the
  folder check is made again and the axes stop says what changed.
- Refusal helpers moved to register_checks (600-line rule); install tests
  moved to their own file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbytvF3Gsa85ix8Ne2yMDW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants